/*
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋
          http://www.cnblog.com/MiYu
Author By : MiYu
Test      : 1
Program   : heap_test
*/

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
    vector <int> vec;
    for ( int i = 1; i <= 10; ++i ) vec.push_back(i);
    for ( int i = 0; i < 10; ++ i ){
        cout << vec[i] << " ";   
    } cout << endl;
    make_heap ( vec.begin(), vec.end() );
    cout << "\nAfter Make_Heap: " << endl;
    for ( int i = 0; i < 10; ++i ){
        cout << vec[i] << " ";   
    } cout << endl;
    vec.push_back ( 11 );
    cout << "\nAfter Push_Heap: " << endl;
    push_heap (  vec.begin(), vec.end() );
    for ( int i = 0; i < 10; ++i ){
        cout << vec[i] << " ";   
    } cout << endl;
    cout << "\nAfter Pop_Heap: " << endl;
    pop_heap ( vec.begin(), vec.end() );
    for ( int i = 0; i < 11; ++i ){
        cout << vec[i] << " ";   
    } cout << endl;
    cout << "\nMake_heap Again! " << endl;
    make_heap ( vec.begin(), vec.end() );
    cout << "\nAfter Sort_Heap: " << endl;
    sort_heap ( vec.begin(), vec.end() );
    for ( int i = 0; i < 11; ++i ){
        cout << vec[i] << " ";   
    } cout << endl;
    system ( "pause" );
    return 0;    
}
